package com.fulihui.weixinsdk.request.mass;

import com.alibaba.fastjson.JSON;
import com.fulihui.weixinsdk.http.HttpMethodEnum;
import com.fulihui.weixinsdk.model.Mpnews;
import com.fulihui.weixinsdk.request.WeixinRequest;
import com.fulihui.weixinsdk.result.mass.MassSendResult;
import com.google.gson.Gson;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * 群发消息
 * Created by 1 on 2018/1/9.
 */
@Data
public class MassSendRequest extends WeixinRequest<MassSendResult> {
    private transient String access_token;


    /***
     * 填写图文消息的接收者，一串OpenID列表，OpenID最少2个，最多10000个
     */
    private List<String> touser;

    private Mpnews mpnews;


    /***
     * 用于群发的图文消息的media_id
     */
    private String media_id;

    /**
     * 群发的消息类型，图文消息为mpnews，文本消息为text，语音为voice，音乐为music，图片为image，视频为video，卡券为wxcard
     */
    private String msgtype;

    /**
     * 消息的标题
     */
    private String title;

    /**
     * 消息的描述
     */
    private String description;

    /***
     * 视频缩略图的媒体ID
     */
    private String thumb_media_id;
    /****
     *  图文消息被判定为转载时，是否继续群发。 1为继续群发（转载），0为停止群发。 该参数默认为0。
     */
    private Integer send_ignore_reprint;

    private String clientmsgid;

    @Override
    public Map<String, String> urlParam() {
        Map<String, String> param = new TreeMap<>();
        if (StringUtils.isNotBlank(access_token)) {
            param.put("access_token", access_token);
        }
        return param;
    }

    @Override
    protected void childParam() {

    }

    @Override
    public String service() {
        return "https://api.weixin.qq.com/cgi-bin/message/mass/send";
    }

    @Override
    public String urlEndStr() {
        return null;
    }

    @Override
    public MassSendResult parseResult(String respStr) {
        return new Gson().fromJson(respStr, MassSendResult.class);
    }

    @Override
    public HttpMethodEnum httpMethod() {
        return HttpMethodEnum.POST;
    }

    @Override
    public String requestData() {
        return JSON.toJSONString(this);
    }
}
